<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html">
	<meta charset="utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title></title>
</head>
<body erke-hide>
</body>
<script>
/**
 * @param {number[][]} M
 * @return {number[][]}
 */
var imageSmoother = function(M) {
	var N=[];
	for(var i=0;i<M.length;i++){
		N[i]=[];
		for(var j=0;j<M[i].length;j++){
			var sum=0;
			var count=0;
			sum+=M[i][j];
			count++;
			if(i>0&&j>0){
				sum+=M[i-1][j-1];
				count++;
			};
			if(i>0){
				sum+=M[i-1][j];
				count++;
			};
			if(i>0&&j<M[i].length-1){
				sum+=M[i-1][j+1];
				count++;
			};
			if(j>0){
				sum+=M[i][j-1];
				count++;
			};
			if(j<M[i].length-1){
				sum+=M[i][j+1];
				count++;
			};
			if(i<M.length-1&&j>0){
				sum+=M[i+1][j-1];
				count++;
			};
			if(i<M.length-1){
				sum+=M[i+1][j];
				count++;
			};
			if(i<M.length-1&&j<M[i].length-1){
				sum+=M[i+1][j+1];
				count++;
			};
			N[i][j]=parseInt(sum/count);
		};		
	};
    console.log(N);
};
var res=new imageSmoother([[2,3,4],[5,6,7],[8,9,10],[11,12,13],[14,15,16]]);
</script>
</html>